Customizing double-click action for widgets in the My Widgets sidebar panel Added by ~Rebecca Lopgerosterjip on January 21, 2011 | Version 1
|
|
There are a couple ways to customize what happens when you double-click on a widget in the My Widgets panel. The widgets framework has a default double-click action which can be overridden by a preference. Some widgets types do not support the default double-click action and thus provide their own double-click action. Changes to the default double-click action will not affect these widget types. Finally, each widget can specify a custom double-click action to take which will override the default double-click action.
The default double-click action is to open the widget in a New Window.
The default double-click action is configurable by using the preference com.ibm.rcp.toolbox/doubleClickAction (as of 8.5.2).
Valid values are:
- sideBar
- newWindow
- float
- tab
- Web Widgets, Feed Widgets, and Google Gadget Widgets all support all four of the doubleClickAction values.
- Notes Widgets (Document, View, and XPage), do not support the 'float' doubleClickAction value. If the doubleClickAction value is set to float, double-clicking on these widget types will open the widget in a New Window.
- Notes Form Widgets do not support any of the doubleClickAction values. This widget type provides its own double-click action which does end up opening the widget in a Tab.
- Composite Application Widgets also do not support any of the doubleClickAction values. This widget type provides its own double-click action which does end up opening the widget (the application) in a Tab.
- Provisioning (Feature and Plug-in) Widgets, by default, do not being opened at all. Thus, there is no double-click action provided.
For all widget types, you can customize the double-click action (as of 8.5.1) to execute an eclipse command that has been added to the client. This custom double-click action will override the doubleClickAction preference.
To add a custom double-click handler, you need to export your widget and modify the xml. After editing the xml, re-import the widget.
In the exported xml, find the palleteItem element and add a doubleClickCommandId attribute. This attribute specifies the id of an eclipse command (org.eclipse.ui.commands extension point) to execute when you double click on the widget.
doubleClickCommandId="com.test.MyDblClickCommand" ...
See eclipse documentation on how to use the org.eclipse.ui.commands extension point.
The IHandler that you implement for your command will be executed. The ExecutionEvent.getParameters() API will return a Map. The Map will contain only one entry: a Properties object with id of widget.transformed.preferences. This Properties object contains all the widget properties (if any). If any widget properties required a transform, the values in the result will be the transformed value (see documentation on transformations using ${date:xyz} and ${name:cn}).
Sample code in your Ihandler:
public Object execute(ExecutionEvent event) throws ExecutionException {
Map map = event.getParameters();
Properties props = (Properties)map.get("widget.transformed.preferences");
Enumeration enumx = props.keys();
while(enumx.hasMoreElements()){
String name = (String)enumx.nextElement();
String val = props.getProperty(name);
System.out.println(name+" = "+val);
}
do something
...
} |